<?php

namespace App\Repositories;


use App\Interfaces\CaptchaService;
use Gregwar\Captcha\CaptchaBuilder;
use Session,Log;

class CaptchaRepository implements CaptchaService{


    /**
     * 生成验证码
     * @param $tmp
     * @return mixed
     */
    public function captcha($tmp){
        $builder = new CaptchaBuilder();

        //图片效果设置样放在 build 方法前面
        $builder->setMaxBehindLines(2);                 //背景干扰线
        $builder->setMaxFrontLines(0);                  //前置干扰线
        $builder->setMaxOffset(6);                      //设置偏移值
        $builder->setDistortion(false);                //是否失真
        //$builder->setBackgroundImages();                //设置背景图片
        //$builder->setInterpolation(false);              //Enable/Disables the interpolation
        //$builder->setMaxAngle();                        //最大倾斜角度
        //$builder->setBackgroundColor(96,96,96);         //背景色
        //$builder->setTextColor(255,255,255);            //文字颜色
        //$builder->setIgnoreAllEffects(true);            //是否禁用所有干扰（干扰线、失真）
        //$builder->setPhrase('123456');                  //设置验证码的值

        //可以设置图片宽高及字体
        $builder->build($width = 100, $height = 38, $font = null);

        //获取验证码的内容
        $phrase = $builder->getPhrase();

        //把内容存入session
//        Session::put('milkcaptcha', $phrase);
        Session::flash('milkcaptcha', $phrase);
        //生成图片
        header("Cache-Control: no-cache, must-revalidate");
        header('Content-Type: image/jpeg');
        $builder->output();
        $builder->inline();
    }



}//end class GoodsRepository